<?php 	include("head.php");
		include_once("paging_function.php");
?>
<script language="JavaScript">

function changeUrl(indexalpha)
{
var url='adspacemgt.php?index='+indexalpha;
window.location=url;
}
</script>

<?php
/////////////////////////////////PAGING /////////////////
 	if(isset($_GET['page']) && $_GET['page']!='')
		{
		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
$limit=$adminpagelimit;
/////////////////////////////////////////////////////////////////	
?>
<?php
////////////////////////////////////////////    Block_---- DELETE  ///////////
if(isset($_POST['Submit']))
{
	$del=$_POST['del'];
	$no=count($del);
	if($no>0)
	{
	for($i=0;$i<$no;$i++)
	{
		mysql_query("DELETE FROM ".ADSPSCEMASTER."  WHERE adspaceId= '".$del[$i]."' ");
		mysql_query("DELETE FROM ".ADSPACEDETAILS."  WHERE adspaceId= '".$del[$i]."' ");
	}
	echo '<script>window.location="adspacemgt.php?dlt=1"</script>';
	}
		$block=$_POST['count_UPDATE'];
	if($_POST['count_UPDATE']>0)
	{
		for($no_up=0; $no_up<$block;$no_up++)
		{
			if(isset($_POST['block'.$no_up]))
			{
				mysql_query("UPDATE ".ADSPSCEMASTER."  set status='N' WHERE adspaceId='".$_POST['block'.$no_up]."'");
			}
			else
			{
				mysql_query("UPDATE ".ADSPSCEMASTER."  set status='Y' WHERE adspaceId='".$_POST['block_hid'.$no_up]."'");
			}
		}
	echo '<script>window.location="adspacemgt.php?page='.$_GET['page'].'&loop='.$_GET['loop'].'&start='.$_GET['start'].'&blk=1"</script>';
	}
}


?>

<?php
	$searchsql="SELECT * FROM ".SITEMASTER.",".SITEUSERS.",".ADSPSCEMASTER." WHERE ".SITEMASTER.".siteuserId=".SITEUSERS.".siteuserId AND ".ADSPSCEMASTER.".adsiteId=".SITEMASTER.".adsiteId ";
	$param='';

	if(isset($_REQUEST['usersearch']) && $_REQUEST['usersearch']!="")

	{
//  echo '<script>alert("User Search");</script>';

	$searchsql.= " AND  username LIKE '".$_REQUEST['usersearch']."%'";
		if($param == '')
		{
			$param .="usersearch=".$_REQUEST['usersearch'];
		}
		else
		{
			$param .="&usersearch=".$_REQUEST['usersearch'];
		}

	}

	if(isset($_REQUEST['adSiteUrl']) && $_REQUEST['adSiteUrl']!="" )

	{
//echo '<script>alert("Email Search");</script>';
	$searchsql.= " AND  `adSiteUrl` LIKE '".$_REQUEST['adSiteUrl']."%'";
		if($param == '')
		{
			$param .="adSiteUrl=".$_REQUEST['adSiteUrl'];
		}
		else
		{
			$param .="&adSiteUrl=".$_REQUEST['adSiteUrl'];
		}

	}

	if(isset($_REQUEST['spacesearch']) && $_REQUEST['spacesearch']!="")

	{
// echo '<script>alert("Site Search");</script>';
 	$searchsql.= " AND  adSpaceName LIKE '".$_REQUEST['spacesearch']."%'";
		if($param == '')
		{
			$param .="spacesearch=".$_REQUEST['spacesearch'];
		}
		else
		{
			$param .="&spacesearch=".$_REQUEST['spacesearch'];
		}
 
 	}
	if($_REQUEST['index']!='' && isset($_REQUEST['index']))

	{
		if($param == '')
		{
			$param .="index=".$_REQUEST['index'];
		}
		else
		{
			$param .="&index=".$_REQUEST['index'];
		}

		#$param="index=".$_REQUEST['index'];
		$searchsql.=" and username like'".$_REQUEST['index']."%'";
	
	}
	if($_REQUEST['adType']!='' && isset($_REQUEST['adType']))
	{
		if($param == '')
		{
			$param .="adType=".$_REQUEST['adType'];
		}
		else
		{
			$param .="&adType=".$_REQUEST['adType'];
		}

		#$param="index=".$_REQUEST['index'];
		$searchsql.=" and adType ='".$_REQUEST['adType']."'";
		
	}
	if($_REQUEST['selectstatus']!='' && isset($_REQUEST['selectstatus']))
	{
		if($param == '')
		{
			$param .="selectstatus=".$_REQUEST['selectstatus'];
		}
		else
		{
			$param .="&selectstatus=".$_REQUEST['selectstatus'];
		}

		#$param="index=".$_REQUEST['index'];
		$searchsql.=" and ".ADSPSCEMASTER.".status ='".$_REQUEST['selectstatus']."'";
		
	}
	else 
	{
	#$search.="ORDER BY adspaceId  DESC";

 	}

	$searchsql.="ORDER BY adspaceId  DESC limit $page,$limit";	

	#echo $search.'<br><br>';

	$searchquery=mysql_query($searchsql) or die('error1'.mysql_error());
	
?>
<!--<fieldset>
<legend class="LEGEND"><b>AD SPACE MANAGEMENT</b></legend>-->
 <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="border:1px solid #666666">

 <tr><td>&nbsp;</td></tr>

 <tr><td>&nbsp;</td></tr>

 <tr><td>
 <table width="100%" border="0" cellspacing="0" cellpadding="3">
 <tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr> 
		<td height="15" colspan="2" align="center" style="color:#000000;font-size:12px;">
			<font color="#000000"><strong>AD SPACE MANAGEMENT</strong></font>
		</td> 
	</tr>
	<tr style="display:" id="editWin">
		<td colspan='2' id="ShowMsg">
		</td>
	</tr>
	<?php 
	if((isset($_GET['blk']) && $_GET['blk']==1) || (isset($_GET['dlt']) && $_GET['dlt']==1) || (isset($_GET['inst']) && $_GET['inst']==1) || (isset($_GET['updt']) && $_GET['updt']==1) )
	{
	?>
	<tr>
	
		<td colspan='2' style="color:#FF0000">
		<?php 
		if(isset($_GET['blk']) && $_GET['blk']==1)
		{
		echo $msg1="Value Blocked/Unblocked Successfully!!!";
		}
		if(isset($_GET['dlt']) && $_GET['dlt']==1)
		{
		echo $msg1="Value Deleted Successfully!!!";
		}
		
		?></td>
	</tr>
	<?php
	}
	?>
</table>



	<table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod">
	<?php
	if(isset($_REQUEST['action']))
		{
			$detailssql="SELECT * FROM ".SITEMASTER.",".SITEUSERS.",".ADSPSCEMASTER.",".ADSPACEDETAILS." WHERE ".SITEMASTER.".siteuserId=".SITEUSERS.".siteuserId AND ".ADSPSCEMASTER.".adsiteId=".SITEMASTER.".adsiteId AND ".ADSPSCEMASTER.".adspaceId=".ADSPACEDETAILS.".adspaceId  AND ".ADSPSCEMASTER.".adspaceId='".$_REQUEST['adspaceId']."'";
			$detailsquery=mysql_query($detailssql);

			//echo $detailssql;
			$fetch=mysql_fetch_array($detailsquery);

	?>
<tr><td colspan="6" id="edit_section" style="display:;">
<fieldset>
	<legend class="LEGEND"> <?php echo ucfirst($_REQUEST['action']);?>Space </legend>
	
		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
			<tr>
				<td width="27%" align="left" id="admin_text">Space Name</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['adSpaceName'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Space Type</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['adspaceType'];?></td>
			</tr>		
			<tr>
				<td width="27%" align="left" id="admin_text">User Email</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['email'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Space Details</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['spaceDetails'];?></td>
			</tr>

			<tr>
				<td width="27%" align="left" id="admin_text">Display Duration</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['dispDuration'];?>Days</td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Ready Date</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['readyDate'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Min Price</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left">$<?php echo $fetch['minPrice'];?></td>
			</tr>
			<tr>
				<td align="center">&nbsp;</td>
				<td align="center">&nbsp;</td>
				<td align="left">
				<input type="button" value="Close" name="close_frm" id="close_frm" onClick="window.location='adspacemgt.php'" /></td>
			</tr>
		</table>	

</fieldset>
	<?php } ?>
</td></tr>
	
	
	<tr>
	
		<td colspan="8" align="center" style="color:#000000;font-size:12px;"><p><strong style="font-weight: 400">Click on the alphabets to browse User Name</strong><strong style="font-weight: 400"><br>&nbsp;</strong></p><?php include_once("search_alphabets.php");?></td>
	
	</tr>
	<tr>
		<td colspan="8" align="left">
			<form name="FieldSearch" id="FieldSearch" method="POST">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td valign="middle">Search By </td>
					<td valign="middle">Space Name: <input type="text" name="spacesearch" value="<?php echo $_REQUEST['spacesearch'];?>" size="10"></td>
					<td valign="middle">User Name: <input type="text" name="usersearch" value="<?php echo $_REQUEST['usersearch'];?>" size="10"></td>					
					<td valign="middle">Site Url: <input type="text" name="adSiteUrl" value="<?php echo $_REQUEST['adSiteUrl'];?>" size="10"></td>
					<td valign="middle">Type: <select name="adType" id="adType" width="10">
						<option value="" <?php if(!$_REQUEST['adType'] == '') echo 'selected'; ?>>--Select One--</option>
						<option value="banner" <?php if($_REQUEST['adType'] == 'banner') echo 'selected'; ?>>Banner</option>
						<option value="thumbnil" <?php if($_REQUEST['adType'] == 'thumbnil') echo 'selected'; ?>>Thumblil</option>
						<option value="text" <?php if($_REQUEST['adType'] == 'text') echo 'selected'; ?>>Text</option>
						<option value="commercial break" <?php if($_REQUEST['adType'] == 'commercial break') echo 'selected'; ?>>Commercial Break</option>
					</select></td>
					
					<td class="SMALL">SpaceStatus:<select name="selectstatus" class="SMALL" >
						<option value="" selected="selected">Ad Status </option>
						<option value="Y"  <?php if($_REQUEST['selectstatus']== "Y") echo 'selected'; ?>>Active</option>
						<option value="N"  <?php if($_REQUEST['selectstatus'] == "N") echo 'selected'; ?>>Inactive</option>
						<option value="P"  <?php if($_REQUEST['selectstatus'] == "P") echo 'selected'; ?>>Pending</option>
						<option value="B" <?php if($_REQUEST['selectstatus'] == "B") echo 'selected'; ?>>Block</option>
					</select>
					</td>
					<td valign="middle"><input type="submit" name="search" value="Search">&nbsp;&nbsp;<input type="button" name="cancel" value="Clear" onclick="window.location='adspacemgt.php'"></td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
<?php

  if(mysql_num_rows($searchquery)>0)
  	{
	
	?><form name="form_admin_management" action="" method="post">
		<tr bgcolor="#6F8DBC">
			<td width="7%" height="28" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
			<td width="20%" align="left" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Space Name</strong> </td>
			<td width="13%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>User Name</strong></td>
			<td width="28%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Site URL</strong></td>
			<td width="20%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Ad Type</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
	</tr>
	<?php 
			$count=0;
			$sno=1;
			$loop=0;
	while($searcharray=mysql_fetch_array($searchquery))
		{
			$loop++;
			if($loop == 1)
			$bgcolor = "#F0F0FF";
			else 
			$bgcolor = "#CCCCFF";
	?>
		<tr bgcolor="<?php echo $bgcolor; ?>">
			<td height="32" style="color:#000000;font-size:12px;"><strong><?php echo $sno+$_GET['page'];//echo $searcharray['usercode']; ?></strong></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['adSpaceName']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['username']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['adSiteUrl']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;"><?php echo ($searcharray['adType']); ?></td>
			<td align="center" valign="middle"><a href="adspacemgt.php?action=details&adspaceId=<?php echo $searcharray['adspaceId'];?>" ><img src="images/edit_icon.gif" border="0"/></a></td>
			<td align="center" valign="middle"><input type="checkbox" name="block<?php echo $count; ?>" value="<?php echo $searcharray['adspaceId']; ?>" <?php if($searcharray['status']=='N') echo "checked";?> >
				<input type="hidden" name="block_hid<?php echo $count; ?>" value="<?php echo $searcharray['adspaceId'];?>"> <br><strong> <?php 										if($searcharray['status']=='Y')
										{
											echo "Active";
										}
									if($searcharray['status']=='N')
										{
											echo "InActive";
										}									if($searcharray['status']=='P')
										{
											echo "Pending";
										}

									if($searcharray['status']=='B')
										{
											echo "Blocked";
										}
										
										?></td>
			<td align="center" valign="middle"><input type="checkbox" name="del[]" value="<?php echo $searcharray['adspaceId'];?>"></td>
	</tr>
			<?php 
			$count++;
			$sno++;
			if($loop == 2)
				{
				$loop = 0;
				}	
		}
			?>
		<tr>
			<td colspan="4">&nbsp;</td>
			<td colspan="4" align="right"><input type="hidden" name="count_UPDATE" value="<?php echo $count; ?>">
			<input type="submit" name="Submit" value="Update"></td>
		</tr>
		<tr>
			<td colspan="8" align="center" style="color:#FF0000"><?php echo paging($searchsql,$page,$limit,'',$param);?></td>
		</tr>
		<?php
	
	}
	
	else
	
	{
	
	?>
	<tr bgcolor="#6F8DBC">
		<td style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
		<td  align="center" style="color:#ffffff;font-size:12px;"><strong>Site Name</strong></td>
		<td style="color:#ffffff;font-size:12px;"><strong>User Name</strong></td>
		<td style="color:#ffffff;font-size:12px;"><strong>Site URL</strong></td>
		<td  valign="middle" style="color:#ffffff;font-size:12px;"><strong>AdType</strong></td>
		<td  align="center" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>
		<td align="center" style="color:#ffffff;font-size:12px;"><strong>Block</strong></td>
		<td align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
      </tr>
    <tr>
      <td colspan="8" align="left">&nbsp;&nbsp;&nbsp;<strong><font color="#FF0000" class="DISPLAYMESSAGES">No Result Found!</font></strong></td>
    </tr>
    <?php

  	}

  ?>
</form>
  </table>
  </td>
</tr>
</table>
<!--</fieldset>-->
</td>
</tr>
</table>
<?php 

include("foot.php");?>
